<?php
	if(!empty($_GET['nama'])){
		$param_nama=$_GET['nama'];
	}else{
		$param_nama=$_POST['nama'];
	}
?>
<div class="judul_content">Data kabupaten</div>

<form method="post" action="utama.php?module=mod_kabupaten">
	<table class="tbl_cari">
		<tr>
			<td width="65">Pencarian  : </td>
			<td width="200"><input type="text" name="nama" value="<?php echo $param_nama; ?>" class="frm_cari" /></td>
			<td><input name="submit" type="submit" class="submit" value="Cari" /></td>
			<td></td>
			<td align="right"><a href="utama.php?module=mod_kabupaten&view=form_tambah"> <input type="button" value="Tambah Data" class="tambah"></a></td>
		</tr>
	</table>
</form>

<table class="table" border="1">
    <tr>
        <th width="20">No</th>
        <th>Nama Kabupaten</th>
		<th>Provinsi</th>
		<th>Tarif</th>
        <th width="50">Aksi</th>
    </tr>
    <?php
    	$p= new paging ;
		$batas= 10;

		//cek halaman dan posisi halaman
		$posisi = $p ->cariposisi($batas) ;

    	$sttmt = $koneksi->query("select * from kabupaten k inner join provinsi p on k.id_provinsi = p.id_provinsi where kabupaten like '%$param_nama%' order by provinsi, kabupaten limit $posisi,$batas");
    	$no = $posisi + 1;

		while($hasil = $sttmt->fetch(PDO::FETCH_ASSOC)){
    		?>
		    <tr>
		        <td><?php echo $no; ?></td>
		        <td><?php echo $hasil[kabupaten]; ?></td>
				<td><?php echo $hasil[provinsi]; ?></td>
				<td><?php echo $hasil[tarif]; ?></td>
		        <td>
		        	<a href="utama.php?module=mod_kabupaten&view=form_edit&id=<?php echo $hasil[id_kabupaten]; ?>">
						<img src="asset/images/edit.png" title="Edit">
					</a>
		        	<a href="utama.php?module=mod_kabupaten&act=hapus&id=<?php echo $hasil[id_kabupaten]; ?>" onclick="return confirm('Anda yakin ingin Menghapus Data ?')">
		        		<img src="asset/images/delete.png" title="Hapus">
		        	</a>
		        </td>
		    </tr>
    		<?php
    		$no++;
		}
	?>
</table>
<br>
<?php
	$sttmt = $koneksi->query("select * from kabupaten where kabupaten like '%$param_nama%' order by id_kabupaten desc");
	$jumlah_data = $sttmt->rowCount();
	//dapatkan jumlah halaman
	$jumlah_halaman= $p->jumlahhalaman($jumlah_data,$batas);
	//cetak link
	$linkhalaman=$p->navhalaman($_GET['halaman'],$jumlah_halaman,$_SERVER['PHP_SELF']."?module=mod_kabupaten","nama=$param_nama");
	print($linkhalaman);
?>
        